/*
https://leetcode.cn/problems/count-numbers-with-unique-digits/submissions/573828821/
统计各位数字都不相同的数
数位dp
*/

class Solution {
public:
    int countNumbersWithUniqueDigits(int n) {
        if (n == 0)return 1;
		if (n == 1)return 10;
		vector<int>dp(n + 1);
		dp[0] = 1;
		dp[1] = 10;
		for (int i = 2; i <= n; i++) {
			int ans = 1;
			for (int j = 9; j >= 9 - i + 2; j--) {
				ans = ans * j;
			}
			dp[i] = dp[i - 1] + 9 * ans;
		}
		return dp[n];
    }
};